package com.wrh.springbootstudy.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(tags = "使用@GetMapping")
@RestController
@RequestMapping("/GetMapping")
public class GetMappingController {

    @ApiOperation("测试@GetMapping")
    @GetMapping("/test1")
    public String test1() {
        return "测试@GetMapping";
    }

    @ApiOperation(value = "测试传参(省略@RequestParam)", notes = "表单中的字段与方法中的参数名一致的话,会自动设置,可以省略@RequestParam注解")
    @GetMapping("/test2")
    public String test2(String name, int age) {
        return "test2：my name is " +
                name +
                " and my age is " +
                age +
                "\n" +
                "表单中的字段与方法中的参数名一致的话,会自动设置,可以省略@RequestParam注解";
    }

    @ApiOperation(value = "测试传参(必须加上@RequestParam)", notes = "表单中的字段与方法中的参数名不一致的话,必须使用@RequestParam注解，用来映射表单中的字段与方法中的参数")
    @GetMapping("/test2_1")
    public String test2_1(
            @RequestParam(value = "name") String n,
            @RequestParam(name = "age") int a
    ) {
        return "test2：my name is " +
                n +
                " and my age is " +
                a +
                "\n" +
                "表单中的字段与方法中的参数名不一致的话,必须使用@RequestParam注解，用来映射表单中的字段与方法中的参数";
    }

    @ApiOperation(value = "测试@PathVariable", notes = "@PathVariable用于接收请求路径中占位符的值")
    @GetMapping("/test3/{user}/{age}")
    public String test3(
            @PathVariable(name = "user") String user,
            @PathVariable(value = "age") int age) {
        return "test3：my name is " + user + " and my age is " + age;
    }

    @ApiOperation(value = "测试@PostMapping", notes = "啊啊啊")
    @PostMapping("/test4")
    public String test4(
            @RequestParam(name = "user") String user,
            @RequestParam(value = "age") int age) {
        return "test4：my name is " + user + " and my age is " + age;
    }

}
